import Vue from 'vue'
import Vuex from 'vuex'

// 注册插件
Vue.use(Vuex)

// 创建仓库
export default {
    // 状态（在一个对象中如果键值相同，那么我们只用写一个）
    state: {
        menuList: [],
        authorities: [],
        hasRoute: sessionStorage.getItem("hasRoute"),
        editableTabsValue: 'Index',
        editableTabs: [{
            title: '首页',
            name: 'Index',
        }]
    },
    // 同步修改状态中的参数
    mutations: {
        setMenu: (state, menuList) => {
            state.menuList = menuList;
        },
        setAuthorities: (state, authorities) => {
            state.authorities = authorities;
        },
        changeRouteStatus: (state, hasRoute) => {
            state.hasRoute = hasRoute;
            sessionStorage.setItem("hasRoute", hasRoute);
        },
        addTab(state, tab) {
            let index = state.editableTabs.findIndex(e => e.name === tab.name)
            if (index === -1) {
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name
                });
            }
            state.editableTabsValue = tab.name
        },
        RESET_STATE: (state) => {
            state.menuList = []
            state.authorities = []
            state.hasRoute = false
            state.editableTabsValue = 'Index'
            state.editableTabs = [{
                title: '首页',
                name: 'Index',
            }]
        }
    },
    // 异步修改状态中的参数（结束还是调用mutations中的方法）
    actions: {}
}






